package com.AUI
{
	import com.AUI.define.style.*;
	
	import flash.geom.Rectangle;

	/**
	 * AUI Component Style.
	 * @author HuangMinPing
	 * @site www.AminLab.com
	 */
	public class AComponentStyle
	{
		/**
		 * The margin of box model of component.
		 */
		public var margin:EDGES = new EDGES;
		/**
		 * The border of box model of component.
		 */
		public var border:BORDERS = new BORDERS;
		/**
		 * The padding of box model of component.
		 */
		public var padding:EDGES = new EDGES;
		/**
		 * The content of box model of component.
		 */
		public var content:CONTENT = new CONTENT;
		/**
		 * The aphla of component.
		 */
		public var alpha:Number = 1;
		/**
		 * The background of component.
		 */
		public var background:IMAGE = new IMAGE;
		/**
		 * The algin type of childNodes of component.
		 */
		public var align:ALIGN = new ALIGN;
		/**
		 * The gaps of childNodes of component.
		 */
		public var gap:GAP = new GAP;
		/**
		 * The font define of component.
		 */
		public var font:FONT = new FONT;
		/**
		 * The icon define of component.
		 */
		public var icon:IMAGE = new IMAGE;
		/**
		 * Clone to a new style and return.
		 */
		public function clone():AComponentStyle
		{
			var dest:AComponentStyle = new AComponentStyle;
			this.cloneTo(dest);
			return dest;
		}
		/**
		 * Clone to dest style.
		 */
		public function cloneTo(dest:AComponentStyle):void
		{
			dest.align.h = align.h;
			dest.align.v = align.v;
			
			dest.alpha = alpha;
			
			dest.background.solid.alpha = background.solid.alpha;
			dest.background.solid.color = background.solid.color;
			dest.background.image = background.image;
			dest.background.slice.x = background.slice.x;
			dest.background.slice.y = background.slice.y;
			dest.background.slice.width = background.slice.width;
			dest.background.slice.height = background.slice.height;
			
			dest.border.bottom.color = border.bottom.color;
			dest.border.bottom.width = border.bottom.width;
			dest.border.bottom.alpha = border.bottom.alpha;
			
			dest.border.left.color = border.left.color;
			dest.border.left.width = border.left.width;
			dest.border.left.alpha = border.left.alpha;
			
			dest.border.right.color = border.right.color;
			dest.border.right.width = border.right.width;
			dest.border.right.alpha = border.right.alpha;
			
			dest.border.top.color = border.top.color;
			dest.border.top.width = border.top.width;
			dest.border.top.alpha = border.top.alpha;
			
			dest.content.width.type = content.width.type;
			dest.content.width.value = content.width.value;
			dest.content.height.type = content.height.type;
			dest.content.height.value = content.height.value;
			
			dest.gap.h = gap.h;
			dest.gap.v = gap.v;
			
			dest.icon.solid.alpha = icon.solid.alpha;
			dest.icon.solid.color = icon.solid.color;
			dest.icon.image = icon.image;
			
			dest.margin.bottom = margin.bottom;
			dest.margin.left = margin.left;
			dest.margin.right = margin.right;
			dest.margin.top = margin.top;
			
			dest.padding.bottom = padding.bottom;
			dest.padding.left = padding.left;
			dest.padding.right = padding.right;
			dest.padding.top = padding.top;
			
			dest.font.align = font.align;
			dest.font.bold = font.bold;
			dest.font.color = font.color;
			dest.font.family = font.family;
			dest.font.italic = font.italic;
			dest.font.placement = font.placement;
			dest.font.underline = font.underline;
			dest.font.size = font.size;
		}
		/**
		 * Compare.
		 */
		public function compare(dest:AComponentStyle):Boolean
		{
			return (
			dest.align.h == align.h &&
			dest.align.v == align.v &&
			
			dest.alpha == alpha &&
			
			dest.background.solid.alpha == background.solid.alpha &&
			dest.background.solid.color == background.solid.color &&
			dest.background.image == background.image &&
			dest.background.slice.x == background.slice.x &&
			dest.background.slice.y == background.slice.y &&
			dest.background.slice.width == background.slice.width &&
			dest.background.slice.height == background.slice.height &&
			
			dest.border.bottom.color == border.bottom.color &&
			dest.border.bottom.width == border.bottom.width &&
			dest.border.bottom.alpha == border.bottom.alpha &&
			
			dest.border.left.color == border.left.color &&
			dest.border.left.width == border.left.width &&
			dest.border.left.alpha == border.left.alpha &&
			
			dest.border.right.color == border.right.color &&
			dest.border.right.width == border.right.width &&
			dest.border.right.alpha == border.right.alpha &&
			
			dest.border.top.color == border.top.color &&
			dest.border.top.width == border.top.width &&
			dest.border.top.alpha == border.top.alpha &&
			
			dest.content.width.type == content.width.type &&
			dest.content.width.value == content.width.value &&
			dest.content.height.type == content.height.type &&
			dest.content.height.value == content.height.value &&
			
			dest.gap.h == gap.h &&
			dest.gap.v == gap.v &&
			
			dest.icon.solid.alpha == icon.solid.alpha &&
			dest.icon.solid.color == icon.solid.color &&
			dest.icon.image == icon.image &&
			
			dest.margin.bottom == margin.bottom &&
			dest.margin.left == margin.left &&
			dest.margin.right == margin.right &&
			dest.margin.top == margin.top &&
			
			dest.padding.bottom == padding.bottom &&
			dest.padding.left == padding.left &&
			dest.padding.right == padding.right &&
			dest.padding.top == padding.top &&
			
			dest.font.align == font.align &&
			dest.font.bold == font.bold &&
			dest.font.color == font.color &&
			dest.font.family == font.family &&
			dest.font.italic == font.italic &&
			dest.font.placement == font.placement &&
			dest.font.underline == font.underline &&
			dest.font.size == font.size
			);
		}
		/**
		 * Max style attrs.
		 */
		public function mix(attrs:Vector.<ACssStyleAttr>):void
		{
			if(attrs == null)
			{
				return;
			}
			for(var i:int = 0,len:int = attrs.length;i < len;++i)
			{
				var obj:Object = this;
				var attr:ACssStyleAttr = attrs[i];
				var maxL:int = attr.key.length - 1;
				for(var j:int = 0;j < maxL;++j)
				{
					obj = obj[attr.key[j]];
				}
				var name:String = attr.key[maxL];
				if(typeof(obj[name]) != typeof(attr.value))
				{
					throw new Error('123');
				}
				obj[name] = attr.value;
			}
		}
	}
}